package A_

import rx.Notification
import rx.Observable
import rx.Subscriber
import java.util.concurrent.TimeUnit

class amb{


      /**
     * 给定两个ob，镜像赋值 第一个发射事件或者是结束的ob 的行为
     * 简单来说就是哪个ob先开始或者先结束，那么就表现 这个ob的行为，类似做一个符合条件的二选一。
     */
    private fun amb() {
        val o1 = Observable.create(Observable.OnSubscribe<String> { subscriber ->
                subscriber.onNext("ev1")
                subscriber.onCompleted()
        }).delay(10, TimeUnit.MILLISECONDS)

        val o2 = Observable.create(Observable.OnSubscribe<String> { subscriber ->
                subscriber.onNext("notificationData")
                subscriber.onCompleted()
        }).materialize()

        Observable.amb(o2, o1).subscribe(object : Subscriber<Any>() {
            override fun onCompleted() {
                println("onComplete")

            }

            override fun onError(e: Throwable) {

            }

            override fun onNext(o: Any) {
                if (o is Notification<*>)
                println(o.value)
            }
        })
    }
}
